﻿using daonaite.core.Attribute;
using daonaite.DAL.system;
using daonaite.Model.system.role_menu;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace daonaite.services.system
{
    [AutoLoad]
    public class role_menuService
    {
        private readonly D_role_menu rmcz;

        public role_menuService(D_role_menu rmcz)
        {
            this.rmcz = rmcz;
        }

        /// <summary>
        /// 根据角色查询菜单
        /// </summary>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public async Task<sys_role_menu> getbyroleAsync(int roleid)
        {
            var result = await rmcz.getbyroleAsync(roleid);
            return result;
        }

        /// <summary>
        /// 更新菜单项
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task<int> update_mensidAsync(sys_role_menu data)
        {
            var r = await rmcz.getbyroleAsync(data.roleId);
            int count;
            if (r == null)
            {
                count = await rmcz.add(data);
            }
            else
            {
                count = await rmcz.update_mensidAsync(data);
            }


            return count;
        }
    }
}
